<?php
// $Id: $

//include the file with the helper functions
require_once drupal_get_path('module', 'eca_main') . '/includes.inc';

/**
 * Field handler artwork thumbnail
 * 
 * Add creates the complete path to a thumbnail,
 * which includes the folder, and the format.
 */
class artwork_handler_field_file_name extends views_handler_field {
 function construct() {
    parent::construct();
    $this->additional_fields['format'] = array('table' => 'compartdb_media_file', 'field' => 'format');
  } 

  function pre_render( $values ){
   //print_r($this->aliases);
   //print_r($values);
  }

  function render($values) {
    
    $media = new stdClass();
    $media->format = $values->compartdb_media_file_format;
    $media->file_name = $values->compartdb_media_file_file_name;
        
    if( eca_is_image($media) || eca_is_video($media))
    {
      $path = image_thumb_path() . $media->file_name;
      $path .= (eca_is_video($media))?'.gif':'.jpg'; //as all thumbs are jpg?
      return $path;
    }
    else{      
      return drupal_get_path('module', 'eca_main').'/img/no_thumb.png';
    }
  }
}

